package com.qiyu.common.utils;


import com.qiyu.common.dto.common.ResponseDTO;

import static com.qiyu.common.constants.common.ResponseDTOConstants.*;

/**
 * @author linhao
 * @date 2019/7/17
 * @Version V1.0
 */
public class ResponseUtil {

    /**
     * 响应成功
     *
     * @return
     */
    public static ResponseDTO SuccessResponse() {
        return new ResponseDTO(CODE_SUCCESS, MSG_SUCCESS, null);
    }

    /**
     * 响应成功
     *
     * @param data 响应数据
     * @return
     */
    public static <T> ResponseDTO SuccessResponse(T data) {
        return new ResponseDTO(CODE_SUCCESS, MSG_SUCCESS, data);
    }


    /**
     * 参数异常
     *
     * @return
     */
    public static ResponseDTO ErrorParamResponse() {
        return new ResponseDTO(CODE_PARAM_ERROR, PARAM_ERROR, null);
    }

    /**
     * 参数异常
     *
     * @param data 响应数据
     * @return
     */
    public static ResponseDTO ErrorParamResponse(Object data) {
        return new ResponseDTO(CODE_PARAM_ERROR, PARAM_ERROR, data);
    }

    /**
     * 未知异常
     *
     * @return
     */
    public static ResponseDTO UnkownErrorResponse() {
        return new ResponseDTO(CODE_UNKOWN_ERROR, UNKOWN_ERROR, null);
    }

    /**
     * 响应超时
     *
     * @return
     */
    public static ResponseDTO TimeOutResponse() {
        return new ResponseDTO(CODE_TIME_OUT, TIME_OUT, null);
    }

    /**
     * 找不到相关资源
     *
     * @return
     */
    public static ResponseDTO NotFoundResponse() {
        return new ResponseDTO(CODE_NOT_FOUND, NOT_FOUND, null);
    }

    /**
     * 无权限访问
     *
     * @return
     */
    public static ResponseDTO Unauthorized() {
        return new ResponseDTO(CODE_UN_AUTHORIZED, MSG_UN_AUTHORIZED, null);
    }
}
